﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CMP.ERP.BLL;
using CMP.ERP.Model;

namespace CMP.ERP.Admin.Controllers
{
    public class PandianController : Controller
    {
        StockBLL bll = new StockBLL();
        PandiandanBLL pdbll = new PandiandanBLL(); int pageSize = 8;
        //
        // GET: /Pandian/
     
        /// <returns></returns>
        public ActionResult Index()
        {
            int PageIndex = 1;
            ViewBag.PageIndex = PageIndex;
            int count = bll.GetStockCount();
            if (count % pageSize > 0)
            {
                ViewBag.count = count % pageSize + 1;
            }
            else
            {
                ViewBag.count = count % pageSize;
            }

            ViewBag.Commodity_Id = new SelectList(bll.GetCnameAll(), "Commodity_Id", "Commodity_Name");
            ViewBag.WareHose_Id = new SelectList(bll.GetWnameAll(), "WareHose_Id", "WareHose_Name");

            return View(bll.GetStockAll(pageSize, PageIndex).ToList());
        }
        public ActionResult Stock_ShowPage(int id)
        {

            int PageIndex = id;
            ViewBag.PageIndex = PageIndex;
            int count = bll.GetStockCount();
            if (count % pageSize > 0)
            {
                ViewBag.count = count % pageSize + 1;
            }
            else
            {
                ViewBag.count = count % pageSize;
            }

            ViewBag.Commodity_Id = new SelectList(bll.GetCnameAll(), "Commodity_Id", "Commodity_Name");
            ViewBag.WareHose_Id = new SelectList(bll.GetWnameAll(), "WareHose_Id", "WareHose_Name");

            return View("Index", bll.GetStockAll(pageSize, PageIndex));
        }
        public ActionResult PandianShow(int id)
        {
            Stock s = bll.GetStockById(id);
            ViewBag.Commodity_Id = new SelectList(bll.GetCnameAll(), "Commodity_Id", "Commodity_Name", s.Commodity_Id);
            ViewBag.WareHose_Id = new SelectList(bll.GetWnameAll(), "WareHose_Id", "WareHose_Name", s.WareHose_Id);
            return View(s);
        }
        /// <summary>
        /// 实现添加功能
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        public ActionResult AddPandian(PandianList p)
        {
            if(pdbll.AddPandian(p)>0)
            {
                return Content("<script>alert('添加盘点单成功！'); location.href='/Pandiandan/Index'</script>");
            }
            else
            {
                return Content("<script>alert('添加失败！'); location.href='/Pandiandan/Index'</script>");
            }
        }
    }
}
